#include "widget.h"
#include "ui_widget.h"
#include "QPaintEvent"
#include "qpainter.h"
#include "QPen"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}
//重载画图事件函数
void Widget:: paintEvent(QPaintEvent *){

    //实例化画家对象  this指的是绘图的窗口
    QPainter painter(this);
    //设置画笔
    QPen pen(QColor(255,0,0));
    //设置画笔宽度
    pen.setWidth(3);
    //设置画笔风格
    pen.setStyle(Qt::DotLine);
    //让画家使用画笔
    painter.setPen(pen);

    //设置画刷
    QBrush brush(Qt::cyan);
    //设置画刷风格
    brush.setStyle(Qt::Dense7Pattern);
    //画家使用画刷
    painter.setBrush(brush);

    //画线
    painter.drawLine(QPoint(0,0),QPoint(200,200));

    //画圆及椭圆
    painter.drawEllipse(QPoint(100,100),50,50);
    painter.drawEllipse(QPoint(200,200),50,100);

    //画矩形
    painter.drawRect(QRect(50,50,100,100));
    //画文字
    painter.drawText(QRect(10,10,200,200),"好好学习，天天向上");
}

Widget::~Widget()
{
    delete ui;
}

